<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <p>差异化询价</p>
  <script>
    // 定义一个询价处理器对象
    const priceProcessor = {
      // 预售价
      pre(originPrice) {
        if (originPrice >= 100) {
          return originPrice - 20;
        }
        return originPrice * 0.9;
      },
      // 大促价
      onSale(originPrice) {
        if (originPrice >= 100) {
          return originPrice - 30;
        }
        return originPrice * 0.8;
      },
      // 返场价
      back(originPrice) {
        if (originPrice >= 200) {
          return originPrice - 50;
        }
        return originPrice;
      },
      // 尝鲜价
      fresh(originPrice) {
        return originPrice * 0.5;
      },
    };

    // 询价函数
    function askPrice(tag, originPrice) {
      return priceProcessor[tag](originPrice)
    }

    // use
    const price = askPrice('pre', 200)
    console.log(price) // 180

    // 增加一个“新人价”
    priceProcessor.newUser = function (originPrice) {
      if (originPrice >= 100) {
        return originPrice - 50;
      }
      return originPrice;
    }
  </script>
</body>

</html>